import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UTFDataFormatException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JOptionPane;
import javax.swing.text.AbstractDocument.LeafElement;
 
 
public class ClientJava {
     
    public static void main(String[] args) {
         
         
        Socket socket;
        BufferedReader in;
        PrintWriter out;
         
        try {
         
            socket = new Socket(InetAddress.getLocalHost(),2013);   
                System.out.println("Demande de connexion");
                // le Client recoit un message de validation du serveur
                in = new BufferedReader (new InputStreamReader (socket.getInputStream()));
                String message_distant = in.readLine();
                System.out.println(message_distant);
                
                //boucle saisie utilisateur 
                while (true) {
					out= new PrintWriter(socket.getOutputStream());
					String chaine = JOptionPane.showInputDialog("Tapez votre calcul  :");
					
					out.println(chaine);
					out.flush();
					
					//le client recoit une reponse du serveur
					BufferedReader in2 = new BufferedReader(new InputStreamReader(socket.getInputStream()));
					String message_distant2= in2.readLine();
					System.out.println(message_distant2);
					
				}
                 
                //socket.close();
                
        }catch (UnknownHostException e) {
             
            e.printStackTrace();
        }catch (IOException e) {
             
            e.printStackTrace();
        }
    }
 
}